Users
note you can use v chat test server base url is
http://170.178.195.150:81/api/v1/
1 - Register
- URL: {{baseUrl}}user/register
- Method: POST
- Authentication: No access token required
- Content-Type:
form-data
to send image of user in file parameter - Example request data:
{
"email":"example@exmaple.com",
"name": "name",
"password":"hashedPassword",
"file":"image from mutil part"
"fcmToken":"user fcm token or playerId for onsignal"
}
Parameter | Required | Description |
---|---|---|
true | user email | |
name | true | user name |
password | true | user hashed password see how to get it |
file | false | user image if null will user default image |
fcmToken | true | fcmToken for notifications if not exist pass it Out |
- to get hashedPassword you need to the following
- import
crypto-js
or any model that can create SHA512 - import
utf8
to encode this string ${process.env.PASSWORD_HASH_KEY}_$email}
- full code in node js
is
cryptoJs.SHA512(utf8.encode(`${process.env.PASSWORD_HASH_KEY}_${user['email']}`)).toString(),
PASSWORD_HASH_KEY
is string you set it in.env
file in backend code it must besame
in front and backend- if you skip this step user will success register but when he wants to log in again he cant
Example response:
{
"success": true,
"data": {
"_id": "61cd8fb33bd8731be040e103",
"imageThumb": "default_user_image.png",
"createdAt": 1640861592248,
"updatedAt": 1640861592248,
"email": "user1",
"name": "user1",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYxY2Q4ZmIzM2JkODczMWJlMDQwZTEwMyIsImlhdCI6MTY0MDg2MTYxOSwiZXhwIjoxODY3ODgwODYxNjE5fQ.XfR7_-kNptfMyXopiPYgLTojhpI7oRUsK9g06Nc0kBY"
}
}
2 - Login
- URL: {{baseUrl}}user/login
- Method: POST
- Content-Type: JSON
- Authentication: No access token required
- Example request data:
{
"email": "user1",
"password": "user1",
"fcmToken": "fcm token"
}
Parameter | Required | Description |
---|---|---|
true | user email | |
password | true | user password |
fcmToken | true | fcm token if not exist pass it Out |
- to get hashedPassword you need to the following
- import
crypto-js
or any model that can create SHA512 - import
utf8
to encode this string ${process.env.PASSWORD_HASH_KEY}_$email}
- full code in node js
is
cryptoJs.SHA512(utf8.encode(`${process.env.PASSWORD_HASH_KEY}_${user['email']}`)).toString(),
PASSWORD_HASH_KEY
is string you set it in.env
file in backend code it must besame
in front and backend- if you skip this step user will success register but when he wants to log in again he cant Example response:
{
"success": true,
"data": {
"_id": "61cd8fb33bd8731be040e103",
"imageThumb": "default_user_image.png",
"createdAt": 1640861592248,
"updatedAt": 1640861592248,
"email": "user1",
"name": "user1",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYxY2Q4ZmIzM2JkODczMWJlMDQwZTEwMyIsImlhdCI6MTY0MDg2MTYxOSwiZXhwIjoxODY3ODgwODYxNjE5fQ.XfR7_-kNptfMyXopiPYgLTojhpI7oRUsK9g06Nc0kBY"
}
}
3 - Update
- URL: {{baseUrl}}user
- Method: PATCH
- Authentication: Bearer token is required in header in
authorization : Bearer yourToken
- Content-Type:
form-data
to send image of user in file parameter - Example request data:
{
"name": "name",
"file":"image from mutil part"
"fcmToken":"user fcm token or playerId for onsignal"
}
Parameter | Required | Description |
---|---|---|
name | false | user name |
file | false | user image if null will user default image |
fcmToken | false | fcmToken for notifications if not exist pass it Out |
- if any parameter above send then the update will be done on it other will ignore
Example response:
{
"success": true,
"data": {
"_id": "61cd8fb33bd8731be040e103",
"imageThumb": "default_user_image.png",
"createdAt": 1640861592248,
"updatedAt": 1640861592248,
"email": "user1",
"name": "user1 updated name"
}
}